<template>
  <el-dropdown trigger="click" @command="changeLanguage">
    <!-- 这里必须加一个div -->
    <div>
      <svg-icon style="color:#fff;font-size:20px" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <!-- 只有使用 i18n 插件，全局就有一个对象 $i18n -->
      <el-dropdown-item command="zh" :disabled="'zh' === $i18n.locale">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en' === $i18n.locale">en</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>
<script>
import Cookie from 'js-cookie'
export default {
  name: 'Lang',
  methods: {
    changeLanguage(tag) {
      this.$i18n.locale = tag
      // 持久化到本地
      Cookie.set('locale', tag)
      this.$message.success('语言切换成功')
    }
  }
}
</script>
